package com.huyaanalysisplatform.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huyaanalysisplatform.entity.TBlueRay;
import com.huyaanalysisplatform.entity.TLolHotHero;
import com.huyaanalysisplatform.mapper.TBlueRayMapper;
import com.huyaanalysisplatform.service.TBlueRayService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Huadi Group 12
 * @since 2021-08-01
 */
@Service
public class TBlueRayServiceImpl extends ServiceImpl<TBlueRayMapper, TBlueRay> implements TBlueRayService {

    public Map queryAll() {
        List<TBlueRay> tableData = this.list();
        Map map = new HashMap();
        map.put("tableData", tableData);
        return map;
    }

    public Map addBlueRay(TBlueRay tBlueRay) {
        Map map = new HashMap();
        map.put("blueRayMBitRate", tBlueRay.getBlueRayMBitRate());
        List<TBlueRay> tBlueRays = this.listByMap(map);
        if (CollectionUtils.isNotEmpty(tBlueRays)) {
            map.put("code", "1");
            map.put("message", "蓝光使用情况已存在");
            return map;
        }
        if (this.save(tBlueRay)) {
            map.put("code", 0);
            map.put("message", "成功");
            return map;
        } else {
            map.put("code", 1);
            map.put("message", "添加失败");
            return map;
        }
    }

    public Map editBlueRay(TBlueRay tBlueRay) {
        Map map = new HashMap();
        QueryWrapper<TBlueRay> queryWrapper = new QueryWrapper<TBlueRay>()
                .notIn("id", tBlueRay.getId())
                .eq("heroName", tBlueRay.getBlueRayMBitRate());
        List<TBlueRay> tBlueRays = this.list(queryWrapper);
        if (CollectionUtils.isNotEmpty(tBlueRays)) {
            map.put("code", "1");
            map.put("message", "蓝光使用情况已存在");
            return map;
        }
        if (this.updateById(tBlueRay)) {
            map.put("code", 0);
            map.put("message", "成功");
            return map;
        } else {
            map.put("code", 1);
            map.put("message", "添加失败");
            return map;
        }
    }

    public Map deleteBlueRay(String id) {
        if (this.removeById(id)) {
            Map map = new HashMap();
            map.put("code", 0);
            map.put("message", "成功");
            return map;
        } else {
            Map map = new HashMap();
            map.put("code", 1);
            map.put("message", "添加失败");
            return map;
        }
    }
}
